package hengtiansoft.com.myapplication.view;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import hengtiansoft.com.myapplication.BaseActivity;
import hengtiansoft.com.myapplication.R;

/**
 * Created by lu on 16/7/6.
 */
public class EditextView extends BaseActivity {
    EditText t1, t2, t3;
    ImageView image;

    @Override
    public void initView() {
        setContentView(R.layout.editextview);
        t1 = (EditText) findViewById(R.id.editText);
        t2 = (EditText) findViewById(R.id.editText2);
        t3 = (EditText) findViewById(R.id.editText3);
        image = (ImageView) findViewById(R.id.images);
        image.setVisibility(View.INVISIBLE);
    }

    @Override
    public void initData() {
        t1.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    //获取焦点
                    t1.setText("lcf");
                    image.setVisibility(View.GONE);
                } else {
                    image.setVisibility(View.VISIBLE);
                }
            }
        });
        t1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        t2.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                actionId = EditorInfo.IME_ACTION_DONE;
                return false;
            }
        });
    }
}
